home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Utilities / FWCalendar / GetImageInfo.rexx < prev    next >
OS/2 REXX Batch file  |  2001-06-04  |  6KB  |  220 lines

  1. /*
  2. ** $VER: GetImageInfo.rexx 1.0
  3. ** Christian Effenberger <youcan@amclust.de>
  4. ** Usage: rx GetImageInfo.rexx <FILE>
  5. */
  6.  
  7. call addlib('rexxsupport.library', 0, -30, 0)
  8. call addlib('datatypes.library', 0, -30)
  9.  
  10. parse arg FILE
  11. if ~exists(FILE) then exit 10
  12.  
  13. say FILE||' -> '||filetype(FILE)
  14.  
  15. /* Pseudo code start
  16.  
  17. Let FOO=''
  18. Let DATA=''
  19. Let PICW=0
  20. Let PICH=0
  21. Let OFFSET=0
  22. Let SPACES=Char(32)||Char(160)||Char(9)||Char(10)||Char(12)||Char(13)
  23. Let IMAGE=UpperCase(FILETYPE(FILE))
  24.  
  25. If Match(IMAGE,"ILBM","DEEP","RGBN","RGB8")
  26.     If READBLOCK(FILE)=TRUE
  27.         Let OFFSET=FindChars(DATA,CharsToHex("BMHD"))
  28.         If OFFSET>0
  29.             Let OFFSET=OFFSET+16
  30.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  31.             Let OFFSET=OFFSET+4
  32.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  33.         Else
  34.             Let OFFSET=FindChars(DATA,CharsToHex("DGBL"))
  35.             If OFFSET>0
  36.                 Let OFFSET=OFFSET+16
  37.                 Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  38.                 Let OFFSET=OFFSET+4
  39.                 Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  40.             EndIf
  41.         EndIf
  42.     Else
  43.         exit 20
  44.     EndIf
  45. ElseIf IMAGE="JPEG"
  46.     If READBLOCK(FILE)=TRUE
  47.         Let OFFSET=FindChars(DATA,IntegerToHex(4360))
  48.         If OFFSET>0
  49.             Let OFFSET=OFFSET+4
  50.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  51.             Let OFFSET=OFFSET+4
  52.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  53.         Else
  54.             Let OFFSET=FindChars(DATA,IntegerToHex(2824))
  55.             If OFFSET>0
  56.                 Let OFFSET=OFFSET+4
  57.                 Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  58.                 Let OFFSET=OFFSET+4
  59.                 Let ,PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  60.             EndIf
  61.         EndIf
  62.     Else
  63.         exit 20
  64.     EndIf
  65. ElseIf IMAGE="GIF"
  66.     If READBLOCK(FILE)=TRUE
  67.         Let OFFSET=FindChars(DATA,CharsToHex("GIF"))
  68.         If OFFSET>0
  69.             Let OFFSET=OFFSET+12
  70.             Let PICW=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  71.             Let OFFSET=OFFSET+4
  72.             Let PICH=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  73.         EndIf
  74.     Else
  75.         exit 20
  76.     EndIf
  77. ElseIf IMAGE="PCX"
  78.     If READBLOCK(FILE)=TRUE
  79.         Let OFFSET=FindChars(DATA,CharsToHex("IHDR"))
  80.         If OFFSET>0
  81.             Let OFFSET=OFFSET+12
  82.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  83.             Let OFFSET=OFFSET+8
  84.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  85.         EndIf
  86.     Else
  87.         exit 20
  88.     EndIf
  89. ElseIf IMAGE="PNG"
  90.     If READBLOCK(FILE)=TRUE
  91.         Let OFFSET=FindChars(DATA,CharsToHex("IHDR"))
  92.         If OFFSET>0
  93.             Let OFFSET=OFFSET+12
  94.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  95.             Let OFFSET=OFFSET+8
  96.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  97.         EndIf
  98.     Else
  99.         exit 20
  100.     EndIf
  101. ElseIf IMAGE="TIFF"
  102.     If READBLOCK(FILE)=TRUE
  103.         Let OFFSET=FindChars(DATA,"4D4D002A")
  104.         If OFFSET>0
  105.             Let OFFSET=OFFSET+60
  106.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  107.             Let OFFSET=OFFSET+24
  108.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  109.         Else
  110.             Let OFFSET=FindChars(DATA,"49492A00")
  111.             If OFFSET>0
  112.                 Let OFFSET=OFFSET+60
  113.                 Let PICW=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  114.                 Let OFFSET=OFFSET+24
  115.                 Let PICH=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  116.             EndIf
  117.         EndIf
  118.     Else
  119.         exit 20
  120.     EndIf
  121. ElseIf IMAGE="TARGA"                /* IMAGE Value = 'Targa' */
  122.     If READBLOCK(FILE)=TRUE
  123.         Let OFFSET=FindChars(DATA,"43")
  124.         If OFFSET>0
  125.             Let OFFSET=OFFSET+24
  126.             Let PICW=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  127.             Let OFFSET=OFFSET+4
  128.             Let PICH=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  129.         EndIf
  130.     Else
  131.         exit 20
  132.     EndIf
  133. ElseIf GetChars(IMAGE,1,3)="SUN"    /* IMAGE Value = 'SUN Raster' */
  134.     If READBLOCK(FILE)=TRUE
  135.         Let OFFSET=FindChars(DATA,"59A66A")
  136.         If OFFSET>0
  137.             Let OFFSET=OFFSET+12
  138.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  139.             Let OFFSET=OFFSET+8
  140.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  141.         EndIf
  142.     Else
  143.         exit 20
  144.     EndIf
  145. ElseIf GetChars(IMAGE,1,3)="PBM"    /* IMAGE Value = 'PBM Plus True Color Raw' */
  146.     If READBLOCK(FILE)=TRUE
  147.         Let DATA=HexToChars(DATA)
  148.         Let OFFSET=2
  149.         Let FOO=GetWord(DATA,OFFSET,SPACES)
  150.         While GetChars(FOO,1,1)="#"
  151.             Let OFFSET=OFFSET+1
  152.             Let FOO=GetWord(DATA,OFFSET,SPACES)
  153.         EndLoop
  154.         Let PICW=Integer(GetWord(DATA,OFFSET,SPACES))
  155.         Let PICH=Integer(GetWord(DATA,OFFSET+1,SPACES))
  156.     Else
  157.         exit 20
  158.     EndIf
  159. ElseIf GetChars(IMAGE,1,5)="ADOBE"  /* IMAGE Value = 'Adobe Photoshop®' */
  160.     If READBLOCK(FILE)=TRUE
  161.         Let OFFSET=FindChars(DATA,CharsToHex("8BPS"))
  162.         If OFFSET>0
  163.             Let OFFSET=OFFSET+32
  164.             Let PICH=HexToInteger(GetChars(DATA,OFFSET,4))
  165.             Let OFFSET=OFFSET+8
  166.             Let PICW=HexToInteger(GetChars(DATA,OFFSET,4))
  167.         EndIf
  168.     Else
  169.         exit 20
  170.     EndIf
  171. ElseIf GetChars(IMAGE,1,7)="WINDOWS"/* IMAGE Value = 'Windows Bitmap' */
  172.     If READBLOCK(FILE)=TRUE
  173.         Let OFFSET=FindChars(DATA,CharsToHex("BM"))
  174.         If OFFSET>0
  175.             Let OFFSET=OFFSET+36
  176.             Let PICW=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  177.             Let OFFSET=OFFSET+8
  178.             Let PICH=HexToInteger(GetChars(DATA,OFFSET+2,2)||GetChars(DATA,OFFSET,2))
  179.         EndIf
  180.     Else
  181.         exit 20
  182.     EndIf
  183. Else
  184.  
  185.     say 'ERROR: ErrorText...'
  186.     exit 10
  187.  
  188. EndIf
  189.  
  190. say FILE||' -> '||IMAGE||': '||PICW||'x'||PICH
  191.  
  192.  Pseudo code end   */
  193.  
  194. exit 0
  195.  
  196. FILETYPE: procedure
  197. parse arg FILE
  198. return strip(translate(examinedt(FILE,,var), '', '0'x))
  199.  
  200. READBLOCK: procedure
  201. parse arg FILE
  202. /* Pseudo code start
  203.  
  204. OpenFile FILE,"BUFFER",READONLY ,OLDFILE
  205. IfError
  206.     return FALSE
  207. Else
  208.     FileReadChars "BUFFER",DATA,512,HEX
  209.     IfError
  210.         Close "BUFFER"
  211.         return FALSE
  212.     Else
  213.         Close "BUFFER"
  214.         return TRUE
  215.     EndIf
  216. EndIf
  217.  
  218.  Pseudo code end   */
  219.  
  220.